package com.zmx.doctor.adapter;


import android.app.Activity;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import com.bumptech.glide.Glide;
import com.wang.adapters.adapter.BaseAdapterRvList;
import com.wang.adapters.base.BaseViewHolder;
import com.zmx.doctor.R;
import com.zmx.doctor.pojo.Goods;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GoodsItemAdapter extends BaseAdapterRvList<GoodsItemAdapter.ViewHolder, Goods> {


    public GoodsItemAdapter(Activity activity) {
        super(activity);
    }


    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onBindVH(ViewHolder holder, int listPosition, Goods goods) {

        holder.goods_title.setText(goods.getName());
        holder.goods_detail.setText(Html.fromHtml((goods.getDescribe()), 10));
        Glide.with(mActivity).load(goods.getImg()).into(holder.goods_image);
        holder.goods_price.setText("￥"+goods.getPrice()+"元");
        holder.add_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                goodsItemListener.setGoodsItemListener(goods);

            }
        });

    }

    @NonNull
    @Override
    protected ViewHolder onCreateVH(ViewGroup parent, LayoutInflater inflater) {
        GoodsItemAdapter.ViewHolder holder = new GoodsItemAdapter.ViewHolder(inflater.inflate(R.layout.adapter_goods_item, parent, false));
        return holder;
    }

    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.goods_image)
        ImageView goods_image;
        @BindView(R.id.add_image)
        Button add_image;
        @BindView(R.id.goods_title)
        TextView goods_title;
        @BindView(R.id.goods_detail)
        TextView goods_detail;
        @BindView(R.id.goods_price)
        TextView goods_price;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    public interface goodsItemListener{

        void setGoodsItemListener(Goods g);

    }

    private goodsItemListener goodsItemListener;
    public void setGoodsItemListeners(goodsItemListener goodsItemListener){
        this.goodsItemListener = goodsItemListener;
    }

}

